package com.examination_system.controller;

import com.examination_system.model.entity.User;
import com.examination_system.model.query.UserQuery;
import com.examination_system.service.UserService;
import com.examination_system.service.impl.UserServiceImpl;
import com.examination_system.utils.LogUtil;
import com.examination_system.utils.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

@WebServlet("/edit")
public class EditUserServlet extends HttpServlet {
    private static final Logger LOGGER = LogUtil.getLogger();
    private UserService service = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String idStr = (String) req.getParameter("id");

        if (StringUtils.isNotBlank(idStr)){
           User user =  service.getById(Long.valueOf(idStr));
            req.setAttribute("user", user);
        }
        req.getRequestDispatcher("/edit.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}